/*
 * @Author: sjr
 * @Date: 2021-01-25 22:47:21
 * @LastEditTime: 2021-01-25 23:11:00
 * @LastEditors: sjr
 * @Description: 描述
 * @FilePath: \leetcode\67.二进制求和.js
 */
/*
 * @lc app=leetcode.cn id=67 lang=javascript
 *
 * [67] 二进制求和
 */

// @lc code=start
/**
 * @param {string} a
 * @param {string} b
 * @return {string}
 */
var addBinary = function(a, b) {
  var res = ''
  var addNum = 0
  var cur = 0
  while(a.length < b.length){
    a = '0' + a
  }
  while(b.length < a.length) {
    b = '0' + b
  }
  for (let i = a.length - 1; i >= 0; i--){
    cur = +a[i] + +b[i] + addNum
    if(cur>= 2){
      cur = cur -2
      addNum = 1
    } else {
      addNum = 0
    }

    res = cur + res
  }
  if(addNum) {
    res = addNum + res
  }
  return res
};
// @lc code=end

